import React, { useState, useEffect } from "react";
import { Redirect, Route } from "react-router-dom";
import { connect } from "react-redux";

export default connect(
    //mapStateToProps
    ({ user }) => ({
        isLogin: user.isLogin
    })
)(function PrivateRoute ({ children, isLogin, component: Comp, ...rest }) {
    console.log("isLogin:", isLogin, rest)
    return (
        <Route
            {...rest}
            render={({ location }) => {
                return isLogin ? (
                    <Comp />
                ) : (
                    <Redirect
                        to={{ pathname: "/login", state: { redirect: location.pathname } }}
                    />
                )
            }}
        />
    );
});
